<?php
//关闭事物自动提交
$db->mysqlDB->falseAutoCommit();

//保存接口ID
$bad_id = $route->bodyParams['bad_id'];

//获取请求必传参
$requestParams = $route->bodyParams['ap_request_params'];

//删除请求参数中的请求必传参
unset($route->bodyParams['ap_request_params']);

//增加更新条件
$route->bodyParams['update_where'] = "bad_id";

//更新基本信息
$R1 = $db->mysqlDB->automaticUpdate($route->bodyParams)->update("sys_bussiness_api_docs");

//判断是否需要增加请求参数信息
if(count($requestParams) <= 0){

    $db->mysqlDB->actionCommint();
    $db->mysqlDB->trueAutoCommit();
    $response->responseData(true);

}

//删除原有请求参数信息
$deleteParams = array(
    "delete_where"  => "badrp_badid",
    "badrp_badid"       => $bad_id,
    "isPhysicallyDelete" => "1"
);

//删除原有角色
$R2 = $db->mysqlDB->automaticDelete($deleteParams)->delete("sys_bussiness_api_docs_request_parameter");

//新增请求参数
$addSql = "INSERT INTO sys_bussiness_api_docs_request_parameter";

$keys = "(badrp_badid,badrp_name,badrp_is_must,badrp_rule,badrp_note,badrp_type,badrp_way) VALUES";

$values = "";

for($i=0;$i<count($requestParams);$i++){

    $badrp_name = trim($requestParams[$i]['badrp_name']);
    $badrp_is_must = trim($requestParams[$i]['badrp_is_must']);
    $badrp_rule = trim($requestParams[$i]['badrp_rule']);
    $badrp_note = trim($requestParams[$i]['badrp_note']);
    $badrp_type = trim($requestParams[$i]['badrp_type']);
    $badrp_way = trim($requestParams[$i]['badrp_way']);

    $tmpValue = "(";
    $tmpValue .= $bad_id . ",'" . $badrp_name . "','" . $badrp_is_must . "','" . $badrp_rule . "','" . $badrp_note . "','" . $badrp_type . "','" . $badrp_way . "'";
    $tmpValue .= "),";

    $values .= $tmpValue . "";

}

//拼接最终SQL
$addSql .= $keys .= rtrim($values, ",");

//执行SQL
$R3 = $db->mysqlDB->queryTransaction($addSql);


//判断两个操作是否执行成功
if ($R1 || $R2 || !$R3) {
    $db->mysqlDB->rollBackCommint();
    $response->responseData(false);
}else{
    $db->mysqlDB->actionCommint();
    $db->mysqlDB->trueAutoCommit();
    $response->responseData(true);
}
